package com.sense.kukoo.biz_explore.adapter

import com.sense.kukoo.biz_explore.adapter.provider.*
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.media.watcher.UserWatcher
import com.sense.kukoo.common.repo.bean.SearchBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class SearchAdapter(
    listener: SearchEventListener,
    data: List<SearchBean>
) :
    MultiItemAdapter<SearchBean>(data) {

    var mCurrentMusic: LocalMediaListItemBean? = null
    var mCurrentPlayState: Int = UserWatcher.MusicStateWatcher.STATE_NOT_PLAYING

    private val mSearchResultUserItemProvider = SearchResultUserItemProvider(listener)
    private val mSearchResultContentItemProvider = SearchResultContentItemProvider(listener)

    init {
        addItemProvider(SearchRecommendItemProvider(listener))
        addItemProvider(RecentTitleProvider(listener))
        addItemProvider(RecentItemProvider(listener))
        addItemProvider(mSearchResultContentItemProvider)
        addItemProvider(mSearchResultUserItemProvider)
    }

    override fun getItemType(data: List<SearchBean>, position: Int): Int {
        return data.get(position).type
    }

    fun setCurrentUserId(currentUserId:Long){
        mSearchResultUserItemProvider.setCurrentUserId(currentUserId)
    }

    interface SearchEventListener {
        fun onRecommendItemClick(bean: SearchBean, position: Int, text: String)
        fun onRecentCleanAll()
        fun onRecentItemClick(bean: SearchBean)
        fun onRecentItemDelete(bean: SearchBean)

        fun onSearchResultContentItemClick(bean: SearchBean)
        fun onSearchResultChannelClick(bean: SearchBean)
        fun onSearchResultPlayClick(bean: SearchBean)
        fun onSearchResultFollowClick(bean: SearchBean, position: Int)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mCurrentMusic = music
        //
        mSearchResultContentItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mCurrentPlayState = state
        //
        mSearchResultContentItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }
}